package gui;

import java.awt.HeadlessException;

import javax.swing.GroupLayout;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.GroupLayout.Alignment;

public class SelectFileGUI extends JFrame {

	private P2PGUI gui;
	private JList list;
	public SelectFileGUI(P2PGUI gui) throws HeadlessException {
		super();
		this.gui = gui;
		init();
	}
	
	public void init(){
		this.setSize(501, 386);
		setName("Select FILE to Send");
		setTitle("Select FILE to Send");
		getContentPane().setLayout(null);
		
		JPanel jPanelSendFile = new JPanel();
		jPanelSendFile.setBorder(javax.swing.BorderFactory.createTitledBorder("Which file do you want to send ?"));
		jPanelSendFile.setBounds(20, 20, 438, 317);
		getContentPane().add(jPanelSendFile);
		
		final JFileChooser jFileChooser= new JFileChooser();
		
		jFileChooser.setAutoscrolls(true);
        jFileChooser.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
            	if (evt.getActionCommand().equals(JFileChooser.APPROVE_SELECTION)) {
                    
                    String filePath = jFileChooser.getSelectedFile().getAbsolutePath();
                    gui.treatFileSelected(filePath);
                                       
                    }
                }

          
        });
        
        GroupLayout jPanelSendFileLayout = new GroupLayout(jPanelSendFile);
        jPanelSendFileLayout.setHorizontalGroup(
        	jPanelSendFileLayout.createParallelGroup(Alignment.LEADING)
        		.addGroup(Alignment.TRAILING, jPanelSendFileLayout.createSequentialGroup()
        			.addContainerGap()
        			.addComponent(jFileChooser, GroupLayout.PREFERRED_SIZE, 416, Short.MAX_VALUE))
        );
        jPanelSendFileLayout.setVerticalGroup(
        	jPanelSendFileLayout.createParallelGroup(Alignment.LEADING)
        		.addGroup(jPanelSendFileLayout.createSequentialGroup()
        			.addContainerGap()
        			.addComponent(jFileChooser, GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
        			.addContainerGap())
        );
        jPanelSendFile.setLayout(jPanelSendFileLayout);

	}
	
}
